#!/usr/bin/perl

#====  PROJECT =================================================================
#         NAME:  Circular infection network.
#      PURPOSE:  Test Case for a circular infection network. Also first use of 
#                the new infection object.
#      RETURNS:  True
#===============================================================================

# Initialisation: Basic Circular Network.

use warnings;
use insj_m_network;
use insj_m_parser;
use Math::Random::MT::Perl qw(rand);

use processes::transmission;
use processes::extinction;
use processes::stochastic_loss;
use processes::level_of_infection;
use processes::parasite_specific_immunity;
use processes::parasite_adaption;
use processes::host_specific_immunity;
use processes::host_nonspecific_immunity;

use structures::circular;

# Import parameters by type.
	%parameters = (); $who = ''; $what = '';
	open $file, 'insj_p_circular.ini';
	while(<$file>) {
		chomp;
		@line = split(',');
		if (scalar (@line) != 2) { next; }
		if (/>/) { $what = $line[1]; $who = $line[0]; }
		else { $parameters{$what}{$who}{$line[0]} = $line[1]; }
		}

# Initialize network structure, depth, number of nodes

	$network = initialize_circular({ 'depth' => 2, 'number_of_nodes' => 20 });
	$network -> print;

# Distribute host types.

	while ($node = $network->get_next){
                if (rand(100)>=50){
                        $node->set_state('type','>A',0);
                        $node->set_state('size',$parameters{'host'}{'>A'}{'size'},0);
			}
                else{
                        $node->set_state('type','>B',0);
                        $node->set_state('size',$parameters{'host'}{'>B'}{'size'},0);
                        }
		}

# Initialize infection.

	$node = $network->get_random_node;
	$node -> add_infection(insj_m_infection->new(name => '10#01'));
	$infection = $node->get_next('infection');
	$infection->set_state('adaption', {'>A' => 0.5, '>B' => 0.5}, 0);
	$infection->set_state('type','>WBA',0); 
	$infection->set_state('level of infection', 0.1, 0);

# Evolve network.
	for($generation = 2; $generation <= 100; $generation++){
		print "-------------Generation $generation-----------\n";
		transmission;
		extinction;
		stochastic_loss;
		level_of_infection;
		parasite_specific_immunity;
		parasite_adaption;
		host_specific_immunity;
		host_nonspecific_immunity;
		$network->print;
	}

$network -> export('test_circular.gexf', 'gephi');
